# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=theharvester
pkgver=4.8.2.r145.gf9c061b
pkgrel=1
epoch=1
groups=('blackarch' 'blackarch-recon')
pkgdesc='Python tool for gathering e-mail accounts and subdomain names from different public sources (search engines, pgp key servers).'
url='http://www.edge-security.com/theHarvester.php'
arch=('any')
license=('GPL2')
depends=('python' 'python-requests' 'python-shodan' 'python-texttable'
         'python-beautifulsoup4' 'python-plotly' 'python-pytest' 'python-yaml'
         'python-censys' 'python-grequests' 'flake8' 'python-dnspython'
         'python-mypy_extensions' 'python-netaddr' 'python-aiodns'
         'python-retrying' 'python-aiohttp' 'python-aiosqlite' 'python-uvloop'
         'python-gevent' 'python-lxml' 'python-aiomultiprocess' 'python-orjson'
         'python-typing_extensions' 'python-zope-event' 'python-starlette'
         'python-slowapi' 'python-certifi' 'python-pyppeteer' 'python-fastapi'
         'python-aiofiles' 'python-ujson' 'uvicorn' 'python-playwright'
         'python-dateutil')
makedepends=('git' 'python-build' 'python-pip')
source=("$pkgname::git+https://github.com/laramies/theHarvester.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i "s|'api-keys.yaml',|'/usr/share/theharvester/api-keys.yaml',|g" \
    theHarvester/lib/core.py
}

build() {
  cd $pkgname

  python -m build --wheel --outdir="$startdir/dist"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

	  pip install \
    --verbose \
    --disable-pip-version-check \
    --no-warn-script-location \
    --ignore-installed \
    --no-compile \
    --no-deps \
    --root="$pkgdir" \
    --prefix=/usr \
    --no-index \
    --find-links="file://$startdir/dist" \
    $pkgname

  cp -a theHarvester/data "$pkgdir/usr/share/$pkgname/data"
  install -Dm 644 theHarvester/data/api-keys.yaml\
     "$pkgdir/usr/share/$pkgname/api-keys.yaml"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md README/*.md
  install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname" README/COPYING \
    README/LICENSES

  mv "$pkgdir/usr/bin/theHarvester" "$pkgdir/usr/bin/$pkgname"

  #rm -rf README*

  #cp -a * "$pkgdir/usr/share/$pkgname/"
  #mv "$pkgdir/usr/bin/theHarvester" "$pkgdir/usr/bin/$pkgname"

#  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
#cd /usr/share/$pkgname
#exec python theHarvester.py "\$@"
#EOF

#  chmod +x "$pkgdir/usr/bin/$pkgname"
}

